﻿using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CompilerLib
{
    public class Compile
    {
        private CompilerResults _results;
        public String[] Sources { get; set; }
        public CompilerResults results
        {
            get
            {
                return _results;
            }
        }
        public void Execute(bool generateExecutable, Languages lang,String OutputName)
        {
            CodeDomProvider codeProvider= default(CodeDomProvider);
            switch (lang)
            {
                case Languages.CSharp:
                    codeProvider = CodeDomProvider.CreateProvider("CSharp");
                    break;
                case Languages.VisualBasic:
                    codeProvider = CodeDomProvider.CreateProvider("Visual Basic");
                    break;
                case Languages.JScript:
                    codeProvider = CodeDomProvider.CreateProvider("JScript");
                    break;
                default:
                    break;
            }

            string Output = OutputName;


            System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters();
            parameters.GenerateExecutable = generateExecutable;
            parameters.OutputAssembly = Output;
            _results = codeProvider.CompileAssemblyFromSource(parameters, Sources);


        }
        public CompilerErrorCollection GetErrors()
        {
            return results.Errors;
        }
    }
    public enum Languages
    {
        CSharp, VisualBasic, JScript
    }
}
